﻿using System;
using System.Linq;

namespace Utk.Nlp
{
    class FrequencyClassificator : IClassificator
    {
        private readonly string[] _values;

        public FrequencyClassificator(params string[] values)
        {
            _values = values.Select(_ => _.ToUpper()).ToArray();
        }

        public double Match(string value)
        {
            // TODO : Rewrite, use asymptotic function
            var countMatch = _values.Count(value.ToUpper().Contains);
            return countMatch > 0
                       ? CurveFunction(countMatch)
                       : 0;
        }

        private static double CurveFunction(double x)
        {
            return 1.0 - 1.0/Math.Pow(x + 1, 2);
        }
    }
}